package com.nchu.ft.common.util;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.*;

public class PersonalityScoreCalculator {

    // 计算各维度分数
    public static Map<DimensionType, Integer> calculateDimensionsScore(String jsonStr) throws JsonProcessingException {
        Map<String, Integer> input = new ObjectMapper().readValue(jsonStr, new TypeReference<>() {});
        Map<DimensionType, Integer> results = new LinkedHashMap<>();

        // 转换题目编号格式：q1 -> 1
        Map<Integer, Integer> questionScores = new HashMap<>();
        input.forEach((k, v) -> questionScores.put(Integer.parseInt(k.substring(1)), v));

        // 遍历所有维度进行计算
        for (DimensionType dimension : DimensionType.values()) {
            results.put(dimension, dimension.calculateScore(questionScores));
        }

        return results;
    }
}